package org.example.service.forum;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.baidu.aip.contentcensor.EImgType;
import org.json.JSONException;
import org.json.JSONObject;

public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "59202347";
    public static final String API_KEY = "MyRu6tviGezAk5fvMKETwN1X";
    public static final String SECRET_KEY = "59zFUyd75lmYzDMl8RTPWHyeQKMjXqYW";


//    public void sample(AipContentCensor client) {
//        // 参数为本地图片路径
//        String path = "u1.jpg";
//        JSONObject response = client.imageCensorUserDefined(path, EImgType.FILE, null);
//        System.out.println(response.toString());
//
//        // 参数为url
//        String url = "u1.jpg";
//        response = client.imageCensorUserDefined(url, EImgType.URL, null);
//        System.out.println(response.toString());
//
//        // 参数为本地图片文件二进制数组
//        byte[] file = readImageFile(imagePath);
//        response = client.imageCensorUserDefined(file, null);
//        System.out.println(response.toString());
//    }

    public static void main(String[] args) throws JSONException {
        // 初始化一个AipContentCensor
        AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

//        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理


        JSONObject res = client.textCensorUserDefined("小学");
        System.out.println(res.toString(2));

        
    }
}